package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;
import com.example.myapplication.ShuJu.BuslistBean;

import java.util.List;

import smartbus.CustomshuttleActivity;

public class BuslistApter extends RecyclerView.Adapter<BuslistApter.Myhot> {

    private Context context;
    private List<BuslistBean.RowsBean> list;

    public BuslistApter(Context context, List<BuslistBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_buslist,null);
        return new BuslistApter.Myhot(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull Myhot holder, int position) {
        holder.startTime.setText("起 :"+list.get(position).getStartTime());
        holder.endTime.setText("末 :"+list.get(position).getEndTime());
        holder.first.setText(list.get(position).getFirst());
        holder.end.setText(list.get(position).getEnd());
        holder.price.setText(String.valueOf(list.get(position).getPrice())+"￥");
        //进入定制班车
        holder.re_buslist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, CustomshuttleActivity.class);
                intent.putExtra("CustomshuttleActivityID",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class Myhot extends RecyclerView.ViewHolder{

        private final TextView startTime;
        private final TextView endTime;
        private final TextView first;
        private final TextView end;
        private final TextView price;
        private final RelativeLayout re_buslist;

        public Myhot(@NonNull View itemView) {
            super(itemView);
            startTime = itemView.findViewById(R.id.startTime);
            endTime = itemView.findViewById(R.id.endTime);
            first = itemView.findViewById(R.id.first);
            end = itemView.findViewById(R.id.end);
            price = itemView.findViewById(R.id.price);
            re_buslist = itemView.findViewById(R.id.re_buslist);
        }
    }
}
